package ${projectPackage}.mvc.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.apache.commons.lang3.Validate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.feeling.admin.base.service.IQueryService;
import com.feeling.admin.base.service.ITransService;
import com.feeling.admin.common.constants.BankDict;
import ${projectPackage}.model.${modelName}AddForm;
import ${projectPackage}.model.${modelName}InfoForm;
import ${projectPackage}.model.${modelName}ListForm;

/**
 * @author ${authName}
 * @date ${createDate}
 */
@RestController
@RequestMapping("/api/v1/${lowModelName}")
public class ${modelName}Controller {
	@Autowired
	private IQueryService ${lowModelName}InfoQueryService;
	@Autowired
	private IQueryService ${lowModelName}ListQueryService;
	@Autowired
	private ITransService ${lowModelName}AddService;
	@Autowired
	private ITransService ${lowModelName}DelService;

	@GetMapping("/info")
	public JSONObject get${modelName}Info(@Valid ${modelName}InfoForm infoForm, HttpServletRequest request) {
		JSONObject jsonObject = new JSONObject();
		Map<String, ?> map = ${lowModelName}InfoQueryService.handle(request, infoForm);
		jsonObject.putAll(map);
		return jsonObject;
	}

	@PostMapping("/list")
	public JSONObject query${modelName}List(@RequestBody @Valid ${modelName}ListForm pageForm, HttpServletRequest request) {
		JSONObject jsonObject = new JSONObject();
		Map<String, ?> map = ${lowModelName}ListQueryService.handle(request, pageForm);
		jsonObject.putAll(map);
		return jsonObject;
	}

	@PostMapping("/addConfirm")
	public JSONObject addDictTypeConfirm(@RequestBody @Valid ${modelName}AddForm addForm, HttpServletRequest request) {
		request.setAttribute(BankDict.PRECHECK, true);
		JSONObject jsonObject = new JSONObject();
		Map<String, ?> map = ${lowModelName}AddService.handle(request, addForm);
		jsonObject.putAll(map);
		return jsonObject;
	}
	
	@PostMapping("/add")
	public JSONObject addDictType(@RequestBody @Valid ${modelName}AddForm addForm, HttpServletRequest request) {
		JSONObject jsonObject = new JSONObject();
		Map<String, ?> map = ${lowModelName}AddService.handle(request, addForm);
		jsonObject.putAll(map);
		return jsonObject;
	}
	
	@PostMapping("/updateConfirm")
	public JSONObject updateDictTypeConfirm(@RequestBody @Valid ${modelName}AddForm addForm, HttpServletRequest request) {
		Validate.notNull(addForm.get${modelName}Seq(), "${lowModelName}Seq不能为空");
		request.setAttribute(BankDict.PRECHECK, true);
		JSONObject jsonObject = new JSONObject();
		Map<String, ?> map = ${lowModelName}AddService.handle(request, addForm);
		jsonObject.putAll(map);
		return jsonObject;
	}
	
	@PostMapping("/update")
	public JSONObject updateDictType(@RequestBody @Valid ${modelName}AddForm addForm, HttpServletRequest request) {
		Validate.notNull(addForm.get${modelName}Seq(), "${lowModelName}Seq不能为空");
		JSONObject jsonObject = new JSONObject();
		Map<String, ?> map = ${lowModelName}AddService.handle(request, addForm);
		jsonObject.putAll(map);
		return jsonObject;
	}
	
	@PostMapping("/del")
	public JSONObject delDictType(@RequestBody @Valid ${modelName}InfoForm infoForm, HttpServletRequest request) {
		JSONObject jsonObject = new JSONObject();
		Map<String, ?> map = ${lowModelName}DelService.handle(request, infoForm);
		jsonObject.putAll(map);
		return jsonObject;
	}
}
